package com.boz.picasa.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.boz.picasa.domain.Account;
import com.boz.tools.ControllerUtils;

/**
 * @author bozj
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    private static final List<Account> ACCOUNTS = new ArrayList<Account>();
    static {
        ACCOUNTS.add(new Account("julienboz", "9map174tir", "crashtete-toot@yahoo.fr"));
        ACCOUNTS.add(new Account("julien.chaise.dieu", "9map174tir", "crashtete-chaisedieu@yahoo.fr"));
    }

    @RequestMapping(method = RequestMethod.GET)
    public List<Account> listAll() {
        return ACCOUNTS;
    }

    @RequestMapping(value = "/{username:.*}")
    public Account getAccountByUsername(@PathVariable final String username) {
        for (final Account account : ACCOUNTS) {
            if (account.getUsername().equals(ControllerUtils.cleanPathVariable(username))) {
                return account;
            }
        }
        return null;
    }
}
